﻿Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.SqlTypes
Imports Microsoft.SqlServer.Server
Imports FileManipulationSQLCLRExternal.SharedObjects

Partial Public Class StoredProcedures
    <Microsoft.SqlServer.Server.SqlProcedure()> _
    Shared Function MSPMoveFile(ByVal SourceFilePath As SqlString, _
                                ByVal SourceFileName As SqlString, _
                                ByVal DestinationFilePath As SqlString, _
                                ByVal DestinationFileName As SqlString, _
                                ByVal OverwriteExistingFileFlag As SqlByte) As Integer
        Try
            Dim _bOverwriteExistingFileFlag As Boolean

            If OverwriteExistingFileFlag = 1 Then
                _bOverwriteExistingFileFlag = True
            Else
                _bOverwriteExistingFileFlag = False
            End If

            MoveFile(CType(SourceFilePath, String), CType(SourceFileName, String), CType(DestinationFilePath, String), CType(DestinationFileName, String), _bOverwriteExistingFileFlag)

            Return 0
        Catch sqlex As SqlException
            ShowError(sqlex.ToString)

            Return 1
        Catch ex As Exception
            ShowError(ex.ToString)

            Return 1
        End Try
    End Function
End Class
